/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Gui;

import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Rainiero
 */
public class RequestHelper {

    public static int GetPageNumber(HttpServletRequest request)
    {
        return getRequestNumber(request, 1, "pageNum");
    }

    public static int GetActivityId(HttpServletRequest request)
    {
        return getRequestNumber(request, "activity");
    }

    public static int GetPaymentId(HttpServletRequest request)
    {
        return getRequestNumber(request, "payment");
    }

    public static int GetCountryId(HttpServletRequest request)
    {
        return getRequestNumber(request, "country");
    }

    public static int GetProjectId(HttpServletRequest request)
    {
        return getRequestNumber(request, "project");
    }

    public static int GetOrganizationId(HttpServletRequest request)
    {
        return getRequestNumber(request, "id");
    }

    private static int getRequestNumber(HttpServletRequest request, String key)
    {
        return getRequestNumber(request, -1, key);
    }

    private static int getRequestNumber(HttpServletRequest request, int defaultValue, String key)
    {
        int result = defaultValue;
        try
        {
            String pageStr = request.getParameter(key);
            result = Integer.parseInt(pageStr);
        }
        catch(Exception ex){}
        return result;
    }

}
